var util = require('../../utils/util.js');
const md = require('../../utils/md5.js');
const app = getApp();
const post = require('../../utils/post.js');
Page({

  data: {
    search: 0
  },
  onLoad: function (options) {
    console.log(options);
    var bankname=options.bankname;
    var city = options.city;
    var that = this;
    that.setData({
      city:city,
      bankname:bankname
    })
    that.chushi(bankname,city);
  },
  searchbank: function () {
    var that = this;
    // 获取成员信息
    var datas = {};
    if (that.data.key == '') {
      that.setData({
        search: 0
      })
      return;
    }
    datas.where = "CBankName like '%" + that.data.key + "%'" + " and CityName=" + that.data.city + " and BankName like '%" + that.data.bankname + "%'";
    var datacall = function (res) {
      console.log(res);
      if (res.data.data.length != 0) {
        that.setData({
          hotinfo: res.data.data,
          search: 1
        })
      }
    }
    var res2 = post.getdata("/BO/BA_BankDetail/Query", datas, datacall);
  },
  getkey: function (e) {
    this.setData({
      key: e.detail.value
    })
  },
  chushi: function (bankname,city) {
    var that = this;
    var datas = {};
    datas.where = datas.where = "CityName =" + city + " and BankName like '%" + bankname + "%'";
    var datacall = function (res) {
      console.log(res);
      if (res.data.data.length != 0) {
        that.setData({
          allinfo: res.data.data
        })
      }
    }
    var res2 = post.getdata("/BO/BA_BankDetail/Query", datas, datacall);
  },
  hot: function () {
    var that = this;
    var datas = {};
    datas.where = "IsMain = 1";
    var datacall = function (res) {
      console.log(res);
      if (res.data.data.length != 0) {
        that.setData({
          hotinfo: res.data.data
        })
      }
    }
    var res2 = post.getdata("/BO/BA_Bank/Query", datas, datacall);
  },
  pinyinpaixu: function (arr) {
    if (!String.prototype.localeCompare)
      return null;

    var letters = "*abcdefghjklmnopqrstwxyz".split('');
    var zh = "阿八嚓哒妸发旮哈讥咔垃痳拏噢妑七呥扨它穵夕丫帀".split('');

    var segs = [];
    var curr;
    letters.forEach(function (item, i) {
      curr = { letter: item, data: [] };
      arr.forEach(function (item2) {
        if ((!zh[i - 1] || zh[i - 1].localeCompare(item2) <= 0) && item2.localeCompare(zh[i]) == -1) {
          curr.data.push(item2);
        }
      });
      if (curr.data.length) {
        segs.push(curr);
        curr.data.sort(function (a, b) {
          return a.localeCompare(b);
        });
      }
    });
    return segs;
  },
  choosebank: function (e) {
    var that = this;
    var cbankname = e.currentTarget.dataset.bank;
    var cbankno = e.currentTarget.dataset.bankcode;
    console.log(cbankname)
    console.log(cbankno)
    wx.setStorageSync('cbankname', cbankname);
    wx.setStorageSync('cbankno', cbankno);
    wx.navigateBack({
      delta: 1
    })
  }
})